package com.sdy.service.Impl;

import com.sdy.dao.mysql.CompanyMapper;
import com.sdy.dao.redis.CompanyDao;
import com.sdy.po.Company;
import com.sdy.service.CompanyService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    CompanyDao companyDao;
    @Resource
    CompanyMapper companyMapper;

    /**
     * 获取客户公司识别码
     * @param companyId
     * @return
     */
    public String getConpanyCodeById(Integer companyId, Boolean ifsetOne){
        System.out.println(companyId);
        String code = companyDao.getConpanyCode(companyId);
        System.out.println("111111" + code);
        if (code == null && ifsetOne){
            String uuid = UUID.randomUUID().toString().substring(0,16);
            if (companyDao.setConpanyCode(companyId,uuid,60) && companyDao.setConnectCode(companyId,uuid,60)){
                return uuid;
            }
            return null;
        }
        return code;
    }

    /**
     * 获得所有的公司信息
     * @return
     */
    @Override
    public List<Company> getAll() {
        return companyMapper.getAll();
    }
}
